package cn.lliiooll.demo;

import cn.lliiooll.demo.command.DemoCommand;
import cn.lliiooll.demo.listener.DemoListener;
import net.mamoe.mirai.console.command.BlockingCommand;
import net.mamoe.mirai.console.command.CommandSender;
import net.mamoe.mirai.console.command.JCommandManager;
import net.mamoe.mirai.console.plugins.Config;
import net.mamoe.mirai.console.plugins.PluginBase;
import net.mamoe.mirai.message.GroupMessage;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

class DemoMain extends PluginBase {

    public static Config config;

    @Override
    public void onLoad() {
        super.onLoad();
        String config_name = "config.yml";
        DemoMain.config = this.loadConfig(config_name);
    }

    @Override
    public void onEnable() {
        super.onEnable();
        this.getEventListener().subscribeAlways(GroupMessage.class, new DemoListener()); // 分开写

        this.getEventListener().subscribeAlways(GroupMessage.class, event -> {
            // 在此放置你的代码
        }); // 不分开写

        JCommandManager.getInstance().register(this, new DemoCommand());
        JCommandManager.getInstance().register(this, new BlockingCommand("指令", new ArrayList<String>() {{
            add("别称1");
            add("别称2");
        }}, "简介", "用法") {
            @Override
            public boolean onCommandBlocking(@NotNull CommandSender commandSender, @NotNull List<String> list) {
                // 在此处理
                return true;// 返回false则会输出用法
            }
        });
        getLogger().info("插件加载完毕!");
    }

    @Override
    public void onDisable() {
        super.onDisable();
        DemoMain.config.save();
    }
}